#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
// ALIASES
using ll = long long;
using ull = unsigned long long;
using ld = long double;
// CONSTANTS
constexpr ld PI = 3.141592653589793238;
constexpr ll INF = 2e18;
constexpr ld EPS = 1e-16;
constexpr ll MOD = 1e9 + 7;
constexpr ll MOD1 = 998244353;
// MACROS
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define pcl pair<char,ll>
#define plc pair<ll,char>
#define vll vector<ll>
#define vc vector<char>
#define vd vector<double>
#define vvll vector<vector<ll>>
#define vvc vector<vector<char>>
#define vvd vector<vector<double>>
#define vpll vector<pair<ll,ll>>
#define vpcc vector<pair<char,char>>
#define all(x) begin(x), end(x)
#define allr(x) rbegin(x), rend(x)
#define Sort(x) sort(all(x))
#define rev_sort(x) sort(all(x),greater<int>())
#define int long long
// SOLVE HERE
void solve(int tests)
{
ll n,k; cin>>n>>k;
vll a(n);
ll pn = 0, nn = 0, z = 0;
for (int i = 0; i < n; ++i){
cin>>a[i]; a[i]-=k;
if(a[i]>0) pn++;
else if(a[i]==0) z++;
else nn++;
}
if(pn == n){
ll op = 0, g;
Sort(a);
g = a[0];
for (int i = 1; i < n; ++i)
g = __gcd(g,a[i]-a[i-1]);
for (int i = 0; i < n; ++i)
op += (a[i]-g)/g;
cout<<op<<'\n';
}
else if(nn == n){
ll op = 0, g;
for (int i = 0; i < n; ++i)
a[i]*=-1;
Sort(a);
g = a[0];
for (int i = 1; i < n; ++i)
g = __gcd(g,a[i]-a[i-1]);
for (int i = 0; i < n; ++i)
op += (a[i]-g)/g;
cout<<op<<'\n';
}
else if(z == n){
cout<<0<<'\n';
}
else cout<<-1<<'\n';
}
// MAIN FUNCTION
int32_t main()
{
auto begin = std::chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cout << setprecision(12) << fixed;
// ifstream cin("input.txt");
// ofstream cout("output.txt");
int tests = 1;
cin >> tests;
for (int tt = 1; tt <= tests; tt++){
// cout<<"~ Test case : "<<tt<<" ~"<<'\n';
solve(tt);
}
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
return 0;
}
791. Custom Sort String | 787. Cheapest Flights Within K Stops |
779. K-th Symbol in Grammar | 701. Insert into a Binary Search Tree |
429. N-ary Tree Level Order Traversal | 739. Daily Temperatures |
647. Palindromic Substrings | 583. Delete Operation for Two Strings |
518. Coin Change 2 | 516. Longest Palindromic Subsequence |
468. Validate IP Address | 450. Delete Node in a BST |
445. Add Two Numbers II | 442. Find All Duplicates in an Array |
437. Path Sum III | 436. Find Right Interval |
435. Non-overlapping Intervals | 406. Queue Reconstruction by Height |
380. Insert Delete GetRandom O(1) | 332. Reconstruct Itinerary |
368. Largest Divisible Subset | 377. Combination Sum IV |
322. Coin Change | 307. Range Sum Query - Mutable |
287. Find the Duplicate Number | 279. Perfect Squares |
275. H-Index II | 274. H-Index |
260. Single Number III | 240. Search a 2D Matrix II |